<?php

namespace CSan\NutrientBundle\Entity;

class FoodRepository extends AbstractRepository
{
    public function createQueryBuilder($alias = '_e', array $params = array())
    {
        $qb = parent::createQueryBuilder($alias, $params);

        // name
        if (isset($params['name']) AND !empty($params['name'])) {
            $like = '%' . str_replace(' ', '%', str_replace('  ', ' ', $params['name'])) . '%';
            $qb->andWhere($qb->expr()->like($alias . '.name', $qb->expr()->literal($like)));
        }

        return $qb;
    }
}